<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/backStageBase.css}">
</head>
<body class="layui-layout-body">
    <div id="backstage" class="layui-layout layui-layout-admin">
        <div class="layui-header layui-bg-blue" >
            <div class="layui-logo">青木良品</div>
            <ul class="layui-nav  layui-layout-left" lay-filter="">
                <li class="layui-nav-item">活动管理</li>
            </ul>
            <ul class="layui-nav layui-layout-right layui-bg-blue">
                <li class="layui-nav-item" th:text="'欢迎你，'+${session.user.name}">
                </li>
                <li class="layui-nav-item"><a href="/mall/user/logout.do">退出</a></li>
            </ul>
        </div>

        <div class="layui-side layui-bg-gray">
            <ul class="layui-nav layui-nav-tree layui-bg-blue" lay-filter="test">
                <!-- 侧边导航: <ul class="layui-nav layui-nav-tree layui-nav-side"> -->
                <li class="layui-nav-item"><a th:href="@{/admin/product/toList.html}">商品管理</a></li>
                <li class="layui-nav-item layui-nav-itemed"><a th:href="@{/admin/activity/toList.html}">活动管理</a></li>
                <li class="layui-nav-item"><a th:href="@{/admin/order/toList.html}">订单管理</a></li>
                <li class="layui-nav-item"><a th:href="@{/admin/user/toList.html}">用户管理</a></li>
            </ul>
        </div>
        <div class="layui-body" style="overflow: hidden;height: 650px">
            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    <li class="layui-this">活动信息</li>
                    <li>添加活动</li>
                </ul>
                <div class="layui-tab-content"  style="height: 650px;">
                    <div class="layui-tab-item layui-show">
                        <table id="activitytList"></table>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" method="post" action="add.do">
                            <div class="layui-form-item">
                                <label class="layui-form-label">活动名称</label>
                                <div class="layui-input-block" style="width: 300px;">
                                    <input type="text" name="activity" required  lay-verify="required" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">活动信息</label>
                                <div class="layui-input-block" style="width: 400px;">
                                    <input name="remark" placeholder="请输入内容" class="layui-input"></input>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">活动折扣</label>
                                <div class="layui-input-block" style="width: 400px;">
                                    <input name="discount" lay-verify="required|number|discount" placeholder="请输入内容" class="layui-input"></input>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        商品分类管理
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script th:src="@{/js/jqurey.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript">
    layui.use(['element','form','table'], function(){
        var element = layui.element;
        var form = layui.form;
        var table = layui.table

        table.render({
            elem: '#activitytList',
            height: 600,
            cols: [ [
                {field: 'id', title: 'ID', width: 60, sort:true},
                {field: 'activity', title: '活动名称', width: 180},
                {field: 'remark', title: '活动信息', width: 230},
                {field: 'discount', title: '活动折扣', width: 120},
                {field: 'state', title: '状态', width: 110, templet:function(d){if(d.status=='0'){return '<span>未进行</span>'}else if(d.status=='1'){return '<span>进行中</span>'}}},
                {field: 'operate', title: '操作', width: 190, templet:function(d){
                        if(d.status=='1'){
                            return '<a href="/mall/admin/activity/toEdit.html?id='+d.id+'"><button class="layui-btn layui-btn-sm">修改</button></a>' +
                                '<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="delacitivity('+d.id+')">删除</button>'
                        }
                    }}
            ]],
            url: 'list.do',
            // parseData: function (res) {
            //     return{
            //         "msg": res.message, //解析提示文本
            //         "data": res.data, //解析数据列表
            //         "count": res.data.length, //解析数据长度
            //     }
            // }
            response: {
                statusName: 'state' //规定数据状态的字段名称，默认：code
                ,statusCode: 0 //规定成功的状态码，默认：0
                ,msgName: 'message' //规定状态信息的字段名称，默认：msg
                ,dataName: 'data' //规定数据列表的字段名称，默认：data
            },
            request: {
                pageName: 'pageindex' //页码的参数名称，默认：page
                ,limitName: 'nums' //每页数据量的参数名，默认：limit
            }
        })
    });
    function delacitivity(id) {
        $.ajax({
            //请求方式
            type : "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "del.do?id="+id,
            //请求成功
            success : function(data) {
                location.reload()
            },
            error : function (e) {

            }
        });
    }
</script>
</html>